Histogram to visualize the distribution of a variable.
See Matplotlib Hist
import matplotlib.pyplot as plt
import numpy as np
plt.style.use('_mpl-gallery')
# make data
np.random.seed(1)
x = 4 + np.random.normal(0, 1.5, 200)
# plot:
fig, ax = plt.subplots()
ax.hist(x, bins=8, linewidth=0.5, edgecolor="white")
ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
ylim=(0, 56), yticks=np.linspace(0, 56, 9))
plt.show()
Box plot to show the distribution of a variable across different categories.
See Nested Boxplot
import seaborn as sns
sns.set_theme(style="ticks", palette="pastel")
# Load the example tips dataset
tips = sns.load_dataset("tips")
# Draw a nested boxplot to show bills by day and time
sns.boxplot(x="day", y="total_bill",
hue="smoker", palette=["m", "g"],
data=tips)
sns.despine(offset=10, trim=True)
Density heatmap to visualize the relationship between total bill and tip, considering factors like sex and smoking status.
import plotly.express as px
import plotly
plotly.offline.init_notebook_mode()
df = px.data.tips()
fig = px.density_heatmap(df, x="total_bill", y="tip", facet_row="sex", facet_col="smoker")
fig.show()
| Package | Plot Type | Description | |
|---|---|---|---|
| Matplotlib | Histogram | Distribution of a variable | |
| Seaborn | Nested Boxplot | Distribution of total bills by day and time, differentiated for smokers and non-smokers | |
| Plotly | Density Heatmap | Relationship between total bill and tip, considering factors like sex and smoking status |